import pytest
import os
import sys
import logging


if __name__ == "__main__":
    if len(sys.argv) ==2:
        #测试环境
        if sys.argv[1] == "test":
            os.environ["ENV"]= "test"
            pass
        # 生产环境
        elif sys.argv[1] == "prod":
            os.environ["URL"] = "http://192.168.10.142/api/cloud-api/auth"
            os.environ["DB"] = str({
                "host": "192.168.10.142",
                "port": 3306,
                "database": "xingyun",
                "user": "root",
                "password": "123456"
            })
            os.environ["ENV"] ="prod"
    else:
        logging.error("请输入正确的执行命令：python run.py test 或者 python run.py prod")

    # 生成测试报告
    pytest.main(["-vs","./testcases/test_runner.py","--alluredir","./report/json_report","--clean-alluredir"])
    os.system("allure generate ./report/json_report -o ./report/html_report --clean")

    from utils.send_feishu_msg import send_feishu_message
    # 报告发送到飞书
    send_feishu_message()